package offer;

class offer26 {
}
class Solution26{
    public static boolean isSubStructure(TreeNode A, TreeNode B) {
        if(A==null||B==null)
            return false;

        boolean flag = dfs(A,B);
        int i = A.val;
        System.out.println(i);
        return flag||isSubStructure(A.left,B)||isSubStructure(A.right,B);
    }

    private static boolean dfs(TreeNode A ,TreeNode B) {
        if(B==null) return true;
        if(A == null)return false;
        if(A.val== B.val&&dfs(A.right,B.right)&&dfs(A.left,B.left))
            return true;
        else return false;
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        TreeNode node1 = new TreeNode(2);
        TreeNode node2 = new TreeNode(3);
        TreeNode node3 = new TreeNode(4);
        TreeNode rootb = new TreeNode(3);
        root.left = node1;
        root.right=  node2;
        node1.left = node3;
        isSubStructure(root,rootb);
    }
}